<template>
  <div>
    <el-upload
      class="upload-demo"
      :action="getFileUrl()"
      name="file"
      :on-change="handleChange"
      :headers="tokenHeader"
      accept=".txt"
      :file-list="fileList"
    >
      点击上传
      <!-- <div slot="tip" class="el-upload__tip">只能上传文件，且不超过500kb</div> -->
    </el-upload>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //这里填写你存储的token
      tokenHeader: { Authorization: localStorage.getItem("token") },
      name: "",
      fileList: [
        {
          name: "food.jpeg",
          url:
            "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100"
        }
      ]
    };
  },
  methods: {
    getFileUrl() {
      //z这里写url地址
      return "http://47.99.59.109/zhoushan/volunteer/apply/upload";
    },
    handleChange(file, fileList) {
      this.name = file.name;
      console.log(file);
      this.fileList = fileList.slice(-3);
    }
  }
};
</script>